package com.jy.wms.controller;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsSoCustomDetailed;
import com.jy.wms.service.WmsSoCustomDetailedService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsSoCustomDetailedController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Fri Dec 29 17:12:16 CST 2017
 */
@Controller
@RequestMapping("/wmssocustomdetailed")
@Api(value = "/wmssocustomdetailed", description = "采购订单附加表明细")
public class  WmsSoCustomDetailedController extends BaseController<WmsSoCustomDetailedService,WmsSoCustomDetailed> {

    @PostMapping(value = "list")
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody ResultPage<WmsSoCustomDetailed> getWmsSoCustomDetailed(@RequestBody WmsSoCustomDetailed entity,HttpSession session) {
        Page<WmsSoCustomDetailed> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody JsonResult deleteWmsSoCustomDetailed(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增采购订单附加表明细信息",response = JSONObject.class, notes = "新增采购订单附加表明细信息")
    public @ResponseBody JSONObject addWmsSoCustomDetailed(@RequestBody WmsSoCustomDetailed entity) {
        try{
            entity.setId(UUIDUtils.uuid());
            baseService.baseInsert(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"新增采购订单附加表明细信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增采购订单附加表明细信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增采购订单附加表明细信息失败", e.getMessage(), "");
        }
    }

    @GetMapping(value = "getWmsSoCustomDetailed/{ssfydmxid}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody JSONObject getWmsSoCustomDetailedById(@PathVariable("ssfydmxid") String ssfydmxid) {
        WmsSoCustomDetailed entity=baseService.baseSelectByPrimaryKey(ssfydmxid);
        return JSONObject.fromObject(entity);
    }
    @GetMapping(value = "getWmsSoCustomDetailedBySsfydid/{sssocid}")
    @ApiOperation(value = "查看所属发运订单明细信息",response = JSONObject.class, notes = "GET查看所属发运订单明细信息")
    public @ResponseBody JSONObject getWmsSoCustomDetailedBySsfydId(@PathVariable("sssocid") String sssocid) {
        JSONObject json=new JSONObject();
        try {
            List<WmsSoCustomDetailed> list = baseService.wmsSoCustomDetailedBySsfydId(sssocid);
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(), (int) list.size());
        }catch (Exception e){
            e.printStackTrace();
        }
        return json;
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑采购订单附加表明细信息",response = JSONObject.class, notes = "编辑采购订单附加表明细信息")
    public @ResponseBody JSONObject editWmsSoCustomDetailed(@RequestBody WmsSoCustomDetailed entity) {
        try{
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"编辑采购订单附加表明细信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑采购订单附加表明细信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑采购订单附加表明细信息失败", e.getMessage(), "");
        }
    }
}
